package org.example.coursemangementserver.server.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.coursemangementserver.common.result.Result;
import org.example.coursemangementserver.pojo.dto.AdminDeleteStudentSelectInfoDTO;
import org.example.coursemangementserver.pojo.dto.IDListDTO;
import org.example.coursemangementserver.pojo.dto.course.*;
import org.example.coursemangementserver.pojo.dto.course.CourseListQuery.GetCourseListDTO;
import org.example.coursemangementserver.pojo.dto.course.EnrollmentListQuery.GetEnrollmentListDTO;
import org.example.coursemangementserver.pojo.dto.course.StudentSelectRecordListQuery.GetStudentSelectRecordListDTO;
import org.example.coursemangementserver.pojo.dto.student.AddStudentInfoDTO;
import org.example.coursemangementserver.pojo.dto.student.EditStudentInfoDTO;
import org.example.coursemangementserver.pojo.dto.student.GetStudentAuditingInfoDTO;
import org.example.coursemangementserver.pojo.dto.student.StudentListQuery.AdminDeleteStudentDTO;
import org.example.coursemangementserver.pojo.dto.student.StudentListQuery.AdminPassStudentDTO;
import org.example.coursemangementserver.pojo.dto.student.StudentListQuery.GetStudentListDTO;
import org.example.coursemangementserver.pojo.dto.teacher.*;
import org.example.coursemangementserver.pojo.dto.teacher.TeacherListQuery.GetTeacherListDTO;
import org.example.coursemangementserver.pojo.vo.course.CommentCourseStatistics.CommentCourseStatisticsVO;
import org.example.coursemangementserver.pojo.vo.course.CourseIdWithName.CourseIdWithNameListVO;
import org.example.coursemangementserver.pojo.vo.course.CourseList.CourseListVO;
import org.example.coursemangementserver.pojo.vo.course.EnrollmentList.EnrollmentListVO;
import org.example.coursemangementserver.pojo.vo.course.SelectCourseStatistics.SelectCourseStatisticsVO;
import org.example.coursemangementserver.pojo.vo.course.StudentSelectRecordList.StudentSelectRecordListVO;
import org.example.coursemangementserver.pojo.vo.course.TeacherCourseRatingStatistics.TeacherCourseRatingStatisticsVO;
import org.example.coursemangementserver.pojo.vo.student.StudentAuditingInfoList.StudentAuditingListInfoVO;
import org.example.coursemangementserver.pojo.vo.student.StudentInfoList.StudentListVO;
import org.example.coursemangementserver.pojo.vo.teacher.TeacherAuditingInfoList.TeacherAuditingListInfoVO;
import org.example.coursemangementserver.pojo.vo.teacher.TeacherIdWithName.TeacherIdWithNameListVO;
import org.example.coursemangementserver.pojo.vo.teacher.TeacherInfoList.TeacherListVO;
import org.example.coursemangementserver.server.service.interfac.admin.AdminService;
import org.example.coursemangementserver.server.service.interfac.student.StudentService;
import org.example.coursemangementserver.server.service.interfac.teacher.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 与管理员操作有关的请求
 */
@RestController
@Slf4j
@RequestMapping("/admin")
public class adminController {
    @Autowired
    private TeacherService  teacherService;
    @Autowired
    private StudentService  studentService;
    @Autowired
    private AdminService adminService;

    @PostMapping("/getTeacherAuditing")
    public Result<TeacherAuditingListInfoVO> getTeacherAuditing(@RequestBody GetTeacherAuditingInfoDTO  getTeacherAuditingInfoDTO) {
        return Result.success(teacherService.getTeacherAuditing(getTeacherAuditingInfoDTO.getPagination()));
    }
    @PostMapping("/getStudentAuditing")
    public Result<StudentAuditingListInfoVO>  getStudentAuditing(@RequestBody GetStudentAuditingInfoDTO getStudentAuditingInfoDTO) {
        return Result.success(studentService.getStudentAuditing(getStudentAuditingInfoDTO.getPagination()));
    }

    /**
     * 根据条件查询获取课程列表
     */
    @PostMapping("/getCourseList")
    public Result<CourseListVO> getArticleList(@RequestBody GetCourseListDTO getArticleListDTO) {
        log.info("正在处理前端获取课程列表请求：{}",getArticleListDTO);
        CourseListVO articleListVO = adminService.getCourseList(getArticleListDTO);
        return Result.success(articleListVO);
    }

    /**
     * 根据课程id更新课程
     */
    @PostMapping("/updateCourse")
    public Result getCourseDetailByCourseName(@RequestBody UpdateCourseDTO updateCourseDTO) {
        log.info("正在处理课程信息更新请求：{}",updateCourseDTO);
        adminService.updateCourseByCourseId(updateCourseDTO);
        return Result.success("课程更新成功");
    }

    /**
     * 根据课程id更新课程
     */
    @PostMapping("/addCourse")
    public Result addCourse(@RequestBody AddCourseDTO addCourseDTO) {
        log.info("正在处理课程信息添加请求：{}",addCourseDTO);
        adminService.addCourse(addCourseDTO);
        return Result.success("课程添加成功");
    }

    /**
     * 根据课程id删除课程
     */
    @PostMapping("/adminDeleteCourse")
    public Result deleteCourse(@RequestBody DeleteCourseDTO deleteCourseDTO) {
        log.info("正在处理课程删除请求：{}",deleteCourseDTO);
        adminService.deleteCourseByCourseId(deleteCourseDTO);
        return Result.success();
    }

    /**
     * 获取所有待选课程信息的请求
     * @param getEnrollmentListDTO
     * @return
     */
    @PostMapping("/getEnrollmentList")
    public Result<EnrollmentListVO> getEnrollmentList(@RequestBody GetEnrollmentListDTO getEnrollmentListDTO) {
        log.info("正在处理前端获取所有待选课程的请求：{}",getEnrollmentListDTO);
        EnrollmentListVO enrollmentListVO = adminService.getEnrollmentList(getEnrollmentListDTO);
        return Result.success(enrollmentListVO);
    }

    /**
     * 获取所有学生信息的请求
     * @param getStudentListDTO
     * @return
     */
    @PostMapping("/getStudentList")
    public Result<StudentListVO> getStudentInfoList(@RequestBody GetStudentListDTO getStudentListDTO) {
        log.info("正在处理前端获取所有学生信息的请求：{}",getStudentListDTO);
        StudentListVO studentListVO = studentService.getStudentList(getStudentListDTO);
        return Result.success(studentListVO);
    }

    /**
     * 获取所有老师信息的请求
     * @param getTeacherListDTO
     * @return
     */
    @PostMapping("/getTeacherList")
    public Result<TeacherListVO> getTeacherInfoList(@RequestBody GetTeacherListDTO getTeacherListDTO) {
        log.info("正在处理前端教务人员获取所有老师信息的请求：{}",getTeacherListDTO);
        TeacherListVO studentListVO = teacherService.getTeacherList(getTeacherListDTO);
        return Result.success(studentListVO);
    }

    /**
     * 教务人员进行结课操作的请求
     * @param endCourseDTO
     * @return
     */
    @PostMapping("/adminEndCourse")
    public Result adminEndCourse(@RequestBody EndCourseDTO endCourseDTO) {
        log.info("进行结课操作的请求：{}", endCourseDTO);
        adminService.adminEndCourse(endCourseDTO);
        return Result.success();
    }

    /**
     * 教务人员查询所有学生的所有选课记录
     * @param getStudentSelectRecordListDTO
     * @return
     */
    @PostMapping("/getStudentSelectRecordList")
    public Result<StudentSelectRecordListVO> getStudentSelectRecord(@RequestBody GetStudentSelectRecordListDTO getStudentSelectRecordListDTO) {
        log.info("教务人员查询所有选课记录：{}",getStudentSelectRecordListDTO);
        StudentSelectRecordListVO  studentSelectRecordListVO = adminService.getStudentSelectRecordList(getStudentSelectRecordListDTO);
        return Result.success(studentSelectRecordListVO);
    }

    /**
     * 教务人员删除某个学生的选课信息
     * @return
     */
    @PostMapping("/deleteStudentSelectInfo")
    public Result deleteStudentSelectInfo(@RequestBody AdminDeleteStudentSelectInfoDTO adminDeleteStudentSelectInfoDTO) {
        adminService.deleteStudentSelectInfo(adminDeleteStudentSelectInfoDTO);
        return Result.success("选课记录信息删除成功");
    }

    /**
     * 教务人员批量删除学生选课记录信息
     * @return
     */
    @PostMapping("/deleteStudentSelectInfoOnList")
    public Result deleteStudentSelectInfoOnList(@RequestBody IDListDTO idListDTO) {
        adminService.deleteStudentSelectInfoOnList(idListDTO);
        return Result.success("选课记录信息删除成功");
    }


    /**
     * 教务人员查询所有学生的课程评价的统计数据
     * @return
     */
    @PostMapping("/statistics/average-ratings")
    public Result<CommentCourseStatisticsVO> getAverageRatings() {
        CommentCourseStatisticsVO commentCourseStatisticsVO = adminService.getCourseCommentAverageRatings();
        return Result.success(commentCourseStatisticsVO);
    }

    /**
     * 教务人员查询所有学生的选课统计数据
     * @return
     */
    @PostMapping("/statistics/select-course")
    public Result<SelectCourseStatisticsVO> getSelectCourseStatistics() {
        SelectCourseStatisticsVO selectCourseStatisticsVO = adminService.getSelectCourseStatisticsVO();
        return Result.success(selectCourseStatisticsVO);
    }

    /**
     * 教务人员获取教师课程评价统计数据
     * @return
     */
    @PostMapping("/statistics/teacher-course-average-ratings")
    public Result<TeacherCourseRatingStatisticsVO> getTeacherCourseAverageRatings() {
        TeacherCourseRatingStatisticsVO teacherCourseAverageRatings = adminService.getTeacherCourseAverageRatings();
        return Result.success(teacherCourseAverageRatings);
    }

    /**
     * 教务人员审核通过教师信息
     * @return
     */
    @PostMapping("/passTeacherInfo")
    public Result passTeacherInfo(@RequestBody AdminPassTeacherDTO adminPassTeacherDTO) {
        adminService.passTeacherInfo(adminPassTeacherDTO);
        return Result.success("教师信息通过成功");
    }
    /**
     * 教务人员审核拒绝通过教师信息
     * @return
     */
    @PostMapping("/deleteTeacherInfo")
    public Result deleteTeacherInfo(@RequestBody AdminDeleteTeacherDTO adminDeleteTeacherDTO) {
        adminService.deleteTeacherInfo(adminDeleteTeacherDTO);
        return Result.success("教师信息删除成功");
    }

    /**
     * 教务人员审核通过学生信息
     * @return
     */
    @PostMapping("/passStudentInfo")
    public Result passStudentInfo(@RequestBody AdminPassStudentDTO adminPassTeacherDTO) {
        adminService.passStudentInfo(adminPassTeacherDTO);
        return Result.success("学生信息通过成功");
    }
    /**
     * 教务人员审核拒绝通过学生信息
     * @return
     */
    @PostMapping("/deleteStudentInfo")
    public Result deleteStudentInfo(@RequestBody AdminDeleteStudentDTO adminDeleteTeacherDTO) {
        adminService.deleteStudentInfo(adminDeleteTeacherDTO);
        return Result.success("学生信息删除成功");
    }

    /**
     * 教务人员批量删除学生信息
     * @return
     */
    @PostMapping("/deleteStudentOnList")
    public Result deleteStudentOnList(@RequestBody IDListDTO idListDTO) {
        adminService.deleteStudentOnList(idListDTO);
        return Result.success("学生信息删除成功");
    }

    /**
     * 教务人员批量删除老师信息
     * @return
     */
    @PostMapping("/deleteTeacherOnList")
    public Result deleteTeacherOnList(@RequestBody IDListDTO idListDTO) {
        adminService.deleteTeacherOnList(idListDTO);
        return Result.success("老师信息删除成功");
    }

    /**
     * 教务人员新增学生信息
     * @return
     */
    @PostMapping("/addStudentInfo")
    public Result addStudentInfo(@RequestBody AddStudentInfoDTO addStudentInfoDTO) {
        adminService.addStudentInfo(addStudentInfoDTO);
        return Result.success("新增学生信息成功");
    }

    /**
     * 教务人员新增老师信息
     * @return
     */
    @PostMapping("/addTeacherInfo")
    public Result addTeacherInfo(@RequestBody AddTeacherInfoDTO addTeacherInfoDTO) {
        adminService.addTeacherInfo(addTeacherInfoDTO);
        return Result.success("新增老师信息成功");
    }

    /**
     * 教务人员编辑学生信息
     * @return
     */
    @PostMapping("/editStudentInfo")
    public Result editStudentInfo(@RequestBody EditStudentInfoDTO editStudentInfoDTO) {
        adminService.editStudentInfo(editStudentInfoDTO);
        return Result.success("编辑学生信息成功");
    }

    /**
     * 教务人员编辑老师信息
     * @return
     */
    @PostMapping("/editTeacherInfo")
    public Result editTeacherInfo(@RequestBody EditTeacherInfoDTO editTeacherInfoDTO) {
        adminService.editTeacherInfo(editTeacherInfoDTO);
        return Result.success("编辑老师信息成功");
    }

    /**
     * 教务人员批量删除课程信息
     * @return
     */
    @PostMapping("/deleteCurseOnList")
    public Result deleteCurseOnList(@RequestBody IDListDTO idListDTO) {
        adminService.deleteCurseOnList(idListDTO);
        return Result.success("课程信息删除成功");
    }

    /**
     * 前台获取所有课程的ID和对应的名字信息
     * @return
     */
    @PostMapping("/getCourseIdWithName")
    public Result<CourseIdWithNameListVO> getCourseIdWithName() {
        CourseIdWithNameListVO  courseIdWithNameListVO = adminService.getCourseIdWithName();
        return Result.success(courseIdWithNameListVO);
    }

    /**
     * 前台获取所有老师的ID和对应的名字信息
     * @return
     */
    @PostMapping("/getTeacherIdWithName")
    public Result<TeacherIdWithNameListVO> getTeacherIdWithName() {
        TeacherIdWithNameListVO  teacherIdWithNameListVO = adminService.getTeacherIdWithName();
        return Result.success(teacherIdWithNameListVO);
    }

    /**
     * 教务人员新增课堂
     * @return
     */
    @PostMapping("/addSelectCourse")
    public Result addSelectCourse(@RequestBody AddSelectCourseDTO addSelectCourseDTO) {
        log.info("教务人员新增课堂：{}",addSelectCourseDTO);
        adminService.addSelectCourse(addSelectCourseDTO);
        return Result.success("成功");
    }

    /**
     * 教务人员编辑选课
     * @return
     */
    @PostMapping("/updateSelectCourse")
    public Result updateSelectCourse(@RequestBody UpdateSelectCourseDTO addSelectCourseDTO) {
        log.info("教务人员编辑选课：{}",addSelectCourseDTO);
        adminService.updateSelectCourse(addSelectCourseDTO);
        return Result.success("成功");
    }
    @PostMapping("/endEnrollmentOnList")
    private Result endEnrollmentOnList(@RequestBody IDListDTO idListDTO){
        adminService.endEnrollmentOnList(idListDTO);
        return Result.success("批量结束课程成功");
    }

    /**
     * 教务人员结束选课
     * @return
     */
    @PostMapping("/adminStopSelectCourse")
    public Result adminStopSelectCourse(@RequestBody AdminStopSelectCourseDTO adminStopSelectCourseDTO) {
        log.info("教务人员结束选课：{}",adminStopSelectCourseDTO);
        adminService.adminStopSelectCourse(adminStopSelectCourseDTO);
        return Result.success("成功");
    }
}
